
import 'dart:async';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:sptapp/api/interface/home_api.dart';
import 'package:sptapp/api/request/response_data.dart';
import 'package:sptapp/config/const.dart';
import 'package:sptapp/moudle/common_info.dart';
import 'package:sptapp/moudle/message.dart';
import 'package:sptapp/moudle/permiss_handler/permission_operate.dart';
import 'package:sptapp/moudle/refresh/my_refresh.dart';
import '../../moudle/event_bus.dart';
import '../index_drawer_page.dart';

class HomeNewPage extends StatefulWidget {
  const HomeNewPage({super.key});

  @override
  State<HomeNewPage> createState() => _HomeNewPageState();
}

class _HomeNewPageState extends State<HomeNewPage> with AutomaticKeepAliveClientMixin{

  String gfbValue = '';
  String gfbUnit = '';
  String dwValue = '';
  String dwUnit = '';
  String fzValue = '';
  String fzUnit = '';
  String cndcValue = '';
  String cndcUnit = '';
  String dcsocValue = '0';
  String dcsocUnit = '';
  String rdynValue = '0';
  String rdynUnit = '';
  String dcdlValue = '-1';
  String moneyUnit = "\$";

  List _list = [];
  late StreamSubscription _subscription;
  late StreamSubscription _devicesubscription;
  late StreamSubscription _Slidersubscription;

  Timer? _timer;
  bool isopen = false;
  bool isData = false;


  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print('initiate=================');
    _getList();
    getBaseUserInfo((){
      if(mounted){
        setState(() {});
      }
    });
    _subscription = eventBus.on<UserInfoChange>().listen((val){
      if(mounted){setState(() {});}
    });
    _devicesubscription = eventBus.on<DeviceInfoChange>().listen((val){
      _getList();
    });
    _Slidersubscription = eventBus.on<IndexSliderChange>().listen((val){
      setState(() {
        isopen = val.isOpen;
      });
    });

    _timer = Timer.periodic(const Duration(seconds: 2), (timer) {
      if(baseDeviceNum != null && baseDeviceNum != ''){
        _getHomeData();
      }
    });
  }

  // _homeViewSHow(){
  //   getBaseUserInfo((){
  //     if(baseUserInfo['equipmentExist'] == false){
  //       _showNoDeviceAlert();
  //     }else if(baseUserInfo['networkExist'] == false){
  //       _showNoNetworkAlert();
  //     }
  //     else{
  //       _getHomeData();
  //     }
  //   });
  // }

  _getList()async{
    getDevicesList((){
      if(baseDevices.isEmpty){
        SmartDialog.dismiss();
        _showNoDeviceAlert();
        setState(() {
            gfbValue = '';
            gfbUnit = '';
            dwValue = '';
            dwUnit = '';
            fzValue = '';
            fzUnit = '';
            cndcValue = '';
            cndcUnit = '';
            dcsocValue = '0';
            dcsocUnit = '';
            rdynValue = '0';
            rdynUnit = '';
            dcdlValue = '-1';
            moneyUnit = "\$";

        });
      }else{
        if(baseDevice?['status'].toString() == '2'){
          SmartDialog.dismiss();
          _showNoNetworkAlert();
          if(mounted){
            setState(() {
              isData = false;
            });
          }
          // return;
        }
        _getHomeData();
      }
    });
  }

  _getHomeData()async{
    ResponseData res = await HomeAPI.getHomeInfo(baseDeviceNum??'');
    if(res.code == 200 && res.data != null){
      isData = true;
      List arr = res.data['DataList'] ?? [];
      for (var item in arr) {
        if(item['code'] == 'BCP'){
          dcsocValue = item['value'] ?? '0';
          dcsocUnit = item['unit'] ?? '';
        }else if(item['code'] == 'D01_31'){
          rdynValue = item['value'] ?? '0';
          rdynUnit = item['unit'] ?? '';
        }else if(item['code'] == 'LPT'){
          fzValue = item['value'] ?? '0';
          fzUnit = item['unit'] ?? '';
        }else if(item['code'] == 'SP1'){
          gfbValue = item['value'] ?? '0';
          gfbUnit = item['unit'] ?? '';
        }else if(item['code'] == 'BCAP'){
          cndcValue = item['value'] ?? '0';
          cndcUnit = item['unit'] ?? '';
        }else if(item['code'] == 'ICT'){
          dwValue = item['value'] ?? '0';
          dwUnit = item['unit'] ?? '';
        }else if(item['code'] == 'BC'){
          dcdlValue = item['value'] ?? '-1';
        }
      }
      if(arr.isEmpty){
         gfbValue = '';
         gfbUnit = '';
         dwValue = '';
         dwUnit = '';
         fzValue = '';
         fzUnit = '';
         cndcValue = '';
         cndcUnit = '';
         dcsocValue = '0';
         dcsocUnit = '';
         rdynValue = '0';
         rdynUnit = '';
         dcdlValue = '-1';
         moneyUnit = "\$";
      }
    }
    if(mounted){
      setState(() {});
    }
  }

  _showNoDeviceAlert(){
    SmartDialog.show(builder: (ctx){
      return Container(
        height: 530.w,
        padding: EdgeInsets.only(left: 48.w,right: 48.w,top: 32.w,bottom: 48.w),
        decoration: BoxDecoration(
            color: Color(0xff1E1E1E),
            borderRadius: BorderRadius.only(topLeft: Radius.circular(32.w),topRight: Radius.circular(32.w))
        ),
        child: Column(
          children: [
            Container(
              child: Row(
                children: [
                  Text('Add new device',style: TextStyle(
                      color: Colors.white,
                      fontSize: 28.sp,
                      fontWeight: FontWeight.w600
                  ),),
                  GestureDetector(
                    onTap: (){
                      SmartDialog.dismiss();
                    },
                    child: Icon(Icons.close,size: 30.sp,color: Color(0xff999999),),
                  )
                ],
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
              ),
            ),
            SizedBox(height: 100.w,),
            GestureDetector(
              onTap: (){
                SmartDialog.dismiss();
                getCameraPermission(context, (){
                  Navigator.of(context).pushNamed('ScanPage').then((val){
                    if(mounted){setState(() {});}
                  });
                });
              },
              child: Container(
                height: 84.w,
                width: 654.w,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    color: themeColor,
                    borderRadius: BorderRadius.circular(8.w)
                ),
                child:Text('Scan Your Device',style: TextStyle(
                    color: Colors.white,
                    fontSize: 28.sp,
                    fontWeight: FontWeight.w600
                ),),
              ),
            ),
            SizedBox(height: 32.w,),
            GestureDetector(
              onTap: (){
                SmartDialog.dismiss();
                Navigator.of(context).pushNamed('MinAddDeviceInput').then((val){
                  if(mounted){setState(() {});}
                });
              },
              child: Container(
                height: 84.w,
                width: 654.w,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    color: Color(0xff2A2A2A),
                    borderRadius: BorderRadius.circular(8.w)
                ),
                child:Text('Manual Entry'.tr,style: TextStyle(
                    color: Colors.white,
                    fontSize: 28.sp,
                    fontWeight: FontWeight.w600
                ),),
              ),
            ),
          ],
        ),
      );
    },alignment: Alignment.bottomCenter);
    // SmartDialog.show(
    //     alignment: Alignment.center,
    //     builder: (BuildContext ctx){
    //       return Container(
    //         decoration: BoxDecoration(
    //           color: Colors.white,
    //           borderRadius: BorderRadius.circular(20.w)
    //         ),
    //         margin: EdgeInsets.symmetric(horizontal: 30.w),
    //         padding: EdgeInsets.symmetric(horizontal: 30.w,vertical: 30.w),
    //         child: Container(
    //           child: Column(
    //             mainAxisSize: MainAxisSize.min,
    //             children: [
    //               Container(
    //                 child: Text(alert_waring_title.tr),
    //               ),
    //               SizedBox(height: 30.w,),
    //               Container(
    //                 child: Text(home_have_no_device_alert_text.tr),
    //               ),
    //               SizedBox(height: 30.w,),
    //               Container(
    //                 child: Row(
    //                   mainAxisAlignment: MainAxisAlignment.spaceAround,
    //                   children: [
    //                     GestureDetector(
    //                       onTap: (){
    //                         SmartDialog.dismiss();
    //                       },
    //                       child: Container(
    //                         width: 200.w,
    //                         height: 90.w,
    //                         alignment: Alignment.center,
    //                         decoration: BoxDecoration(
    //                           color: Colors.grey,
    //                           borderRadius: BorderRadius.circular(20.w)
    //                         ),
    //                         child: Text(alert_waring_canclebtn_text.tr),
    //                       ),
    //                     ),
    //                     GestureDetector(
    //                       onTap: (){
    //                         SmartDialog.dismiss().then((val){
    //
    //                         });
    //                         // Navigator.of(context).pushNamed('AddDevicePage').then((val){
    //                         //   // _homeViewSHow();
    //                         //   _getList();
    //                         // });
    //                       },
    //                       child: Container(
    //                         width: 200.w,
    //                         height: 90.w,
    //                         alignment: Alignment.center,
    //                         decoration: BoxDecoration(
    //                             color: themeColor,
    //                             borderRadius: BorderRadius.circular(20.w)
    //                         ),
    //                         child: Text(alert_waring_surebtn_text.tr),
    //                       ),
    //                     )
    //                   ],
    //                 ),
    //               )
    //             ],
    //           ),
    //         ),
    //       );
    //     }
    // );
  }

  _showNoNetworkAlert(){
    SmartDialog.show(builder: (ctx){
      return Container(
        height: 530.w,
        padding: EdgeInsets.only(left: 48.w,right: 48.w,top: 32.w,bottom: 48.w),
        decoration: BoxDecoration(
            color: Color(0xff1E1E1E),
            borderRadius: BorderRadius.only(topLeft: Radius.circular(32.w),topRight: Radius.circular(32.w))
        ),
        child: Column(
          children: [
            Container(
              child: Row(
                children: [
                  Text('Device Network Settings',style: TextStyle(
                      color: Colors.white,
                      fontSize: 28.sp,
                      fontWeight: FontWeight.w600
                  ),),
                  GestureDetector(
                    onTap: (){
                      SmartDialog.dismiss();
                    },
                    child: Icon(Icons.close,size: 30.sp,color: Color(0xff999999),),
                  )
                ],
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
              ),
            ),
            SizedBox(height: 100.w,),
            GestureDetector(
              onTap: (){
                SmartDialog.dismiss();
                Navigator.of(context).pushNamed('DeviceNetPage').then((val){
                  if(mounted){setState(() {});}
                });
              },
              child: Container(
                height: 84.w,
                width: 654.w,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    color: themeColor,
                    borderRadius: BorderRadius.circular(8.w)
                ),
                child:Text('Select network',style: TextStyle(
                    color: Colors.white,
                    fontSize: 28.sp,
                    fontWeight: FontWeight.w600
                ),),
              ),
            ),
            SizedBox(height: 32.w,),
            GestureDetector(
              onTap: (){
                SmartDialog.dismiss();
                Navigator.of(context).pushNamed('DeviceNetPage').then((val){
                  if(mounted){setState(() {});}
                });
              },
              child: Container(
                height: 84.w,
                width: 654.w,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    color: Color(0xff2A2A2A),
                    borderRadius: BorderRadius.circular(8.w)
                ),
                child:Text('Manual Entry'.tr,style: TextStyle(
                    color: Colors.white,
                    fontSize: 28.sp,
                    fontWeight: FontWeight.w600
                ),),
              ),
            ),
          ],
        ),
      );
    },alignment: Alignment.bottomCenter);
    // SmartDialog.show(
    //     alignment: Alignment.center,
    //     builder: (BuildContext ctx){
    //       return Container(
    //         decoration: BoxDecoration(
    //             color: Colors.white,
    //             borderRadius: BorderRadius.circular(20.w)
    //         ),
    //         margin: EdgeInsets.symmetric(horizontal: 30.w),
    //         padding: EdgeInsets.symmetric(horizontal: 30.w,vertical: 30.w),
    //         child: Container(
    //           child: Column(
    //             mainAxisSize: MainAxisSize.min,
    //             children: [
    //               Container(
    //                 child: Text(alert_waring_title.tr),
    //               ),
    //               SizedBox(height: 30.w,),
    //               Container(
    //                 child: Text(home_have_no_network_alert_text.tr),
    //               ),
    //               SizedBox(height: 30.w,),
    //               Container(
    //                 child: Row(
    //                   mainAxisAlignment: MainAxisAlignment.spaceAround,
    //                   children: [
    //                     GestureDetector(
    //                       onTap: (){
    //                         SmartDialog.dismiss();
    //                       },
    //                       child: Container(
    //                         width: 200.w,
    //                         height: 90.w,
    //                         alignment: Alignment.center,
    //                         decoration: BoxDecoration(
    //                             color: Colors.grey,
    //                             borderRadius: BorderRadius.circular(20.w)
    //                         ),
    //                         child: Text(alert_waring_canclebtn_text.tr),
    //                       ),
    //                     ),
    //                     GestureDetector(
    //                       onTap: (){
    //                         SmartDialog.dismiss();
    //                         Navigator.of(context).pushNamed('DeviceNetPage').then((val){
    //                           // _homeViewSHow();
    //                           _getList();
    //                         });
    //                       },
    //                       child: Container(
    //                         width: 200.w,
    //                         height: 90.w,
    //                         alignment: Alignment.center,
    //                         decoration: BoxDecoration(
    //                             color: themeColor,
    //                             borderRadius: BorderRadius.circular(20.w)
    //                         ),
    //                         child: Text(alert_waring_surebtn_text.tr),
    //                       ),
    //                     )
    //                   ],
    //                 ),
    //               )
    //             ],
    //           ),
    //         ),
    //       );
    //     }
    // );
  }

  String _getImageUrl(int index){
    if(index == 0){
      if(gfbValue != null && gfbValue.isNotEmpty && double.parse(gfbValue) > 0){
        return 'assets/home/home_solar_panel.gif';
      }
      return 'assets/home/home_solar_panel.png';
    }
    if(index == 1){

      if(dwValue != null && dwValue.isNotEmpty && double.parse(dwValue) > 0){
        return 'assets/home/home_grid_bk.gif';
      }
      if(dwValue != null && dwValue.isNotEmpty && double.parse(dwValue) < 0){
        if(gfbValue != null && gfbValue.isNotEmpty && double.parse(gfbValue) > 0){
          return 'assets/home/home_grid.gif';
        }
        return 'assets/home/home_grid.gif'; //修改为灰色
      }
      return 'assets/home/home_grid.png';
    }
    if(index == 2){
      if(cndcValue != null && cndcValue.isNotEmpty && double.parse(cndcValue) < 0){
        return 'assets/home/home_enegry_storage_bk.gif';
      }
      if(cndcValue != null && cndcValue.isNotEmpty && double.parse(cndcValue) > 0){
        if(gfbValue != null && gfbValue.isNotEmpty && double.parse(gfbValue) > 0){
          return 'assets/home/home_enegry_storage.gif';
        }
        return 'assets/home/home_enegry_storage.gif'; //变灰色
      }
      return 'assets/home/home_enegry_storage.png';
    }
    if(index == 3){
      if(fzValue != null && fzValue.isNotEmpty && double.parse(fzValue) > 0){
        if(gfbValue != null && gfbValue.isNotEmpty && double.parse(gfbValue) > 0){
          return 'assets/home/home_out_power.gif';
        }
        return 'assets/home/home_out_power_bk.gif';
      }
      return 'assets/home/home_out_power.png';
    }
    return '';
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _subscription.cancel();
    _devicesubscription.cancel();
    _Slidersubscription.cancel();
    SmartDialog.dismiss();
    _timer?.cancel();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.black,
        body: GestureDetector(
          onTap: (){
            // drawerKey.currentState?.closeSlider();
            // eventBus.fire(IndexSliderChange(false));
            // setState(() {
            //   isopen = false;
            // });
          },
          child: EasyRefresh(
            header: myRefreshHeader(),
            onRefresh: (){
              _getList();
            },
            child: Container(
              padding: EdgeInsets.zero,
              child: Container(
                width: 1.sw,
                height: 1.sh,
                child: Container(
                  width: 1.sw,
                  height: 1.sh,
                  child: Stack(
                    children: [
                      //背景图
                      Container(
                        width: 1.sw,
                        height: 1.sh,
                        child: Image.asset('assets/home/home_new_bg.png',width: 1.sw,height: 1.sh,fit: BoxFit.fitWidth,),
                      ),

                      //顶部信息
                      Positioned(top: ScreenUtil().statusBarHeight+10.w,left: 0,right: 0,
                        child: Container(
                          padding: EdgeInsets.symmetric(horizontal: 30.w),
                          height: 60,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              GestureDetector(
                                onTap: (){
                                  // if(drawerKey.currentState != null && drawerKey.currentState!.isDrawerOpen){
                                  //   drawerKey.currentState?.closeSlider();
                                  //   eventBus.fire(IndexSliderChange(false));
                                  //   setState(() {
                                  //     isopen = false;
                                  //   });
                                  // }else{
                                    eventBus.fire(IndexSliderChange(true));
                                    // drawerKey.currentState?.openSlider();
                                    setState(() {
                                      isopen = true;
                                    });
                                  // }
                                },
                                child: Row(
                                  children: [
                                    Container(
                                      child: Image.asset('assets/home/home_person.png',width: 72.w,),
                                    ),
                                    SizedBox(width: 20.w,),
                                    Visibility(visible: !isopen,child: Container(
                                      constraints: BoxConstraints(
                                          maxWidth: 350.w
                                      ),
                                      child: Text(baseUserInfo['nickname']??'',style: TextStyle(
                                          color: whiteFontColor,
                                          fontSize: 32.sp
                                      ),maxLines: 1,overflow: TextOverflow.ellipsis,),
                                    ),)
                                  ],
                                ),
                              ),
                              Container(
                                child: Image.asset('assets/home/home_logo.png',height: 40.w,),
                              )
                              // GestureDetector(
                              //   onTap: (){
                              //     JhPickerTool.showStringPicker(context,
                              //         data: _list,
                              //         clickCallBack: _selectType,
                              //         normalIndex: 0);
                              //   },
                              //   child: Row(
                              //     children: [
                              //       SizedBox(width: 20.w,),
                              //       Text(home_page_change_device_text.tr,style: TextStyle(
                              //           color: fontColor
                              //       ),)
                              //     ],
                              //   ),
                              // ),
                            ],
                          ),
                        ),
                      ),

                      //左侧信息
                      Positioned(
                          top: 620.h+110/2,
                          left: 1.sw/2 -62/2 - 40.w - 60 ,
                          child: Container(
                            width: 300.w,
                            height: 360.h,
                            child: Stack(
                              children: [
                                Container(
                                  child: Image.asset('assets/home/home_out_power.png',width: 68,),
                                ),
                                Container(
                                  child: Image.asset(_getImageUrl(3),width: 68,),
                                ),
                                Positioned(
                                  bottom: 0,
                                  left: 20,
                                  child: Container(
                                    child: Column(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: [
                                        Row(
                                          crossAxisAlignment: CrossAxisAlignment.end,
                                          children: [
                                            Container(
                                              child: Text('${fzValue.replaceAll("-", "")}',style: TextStyle(
                                                  color: whiteFontColor,
                                                  fontSize:40.sp,
                                                  fontWeight: FontWeight.w600,
                                                  height: 1
                                              ),),
                                              // color: Colors.green,
                                            ),
                                            SizedBox(width: 8.w,),
                                            Container(
                                              // color: Colors.green,
                                              // margin: EdgeInsets.only(bottom: 4.w),
                                              child: Text('${fzUnit}',style: TextStyle(
                                                  color: greyFontColor,
                                                  fontSize: 22.sp,
                                                  fontWeight: FontWeight.w600,
                                                  height: 1
                                              ),),
                                            )
                                          ],
                                        ),
                                        SizedBox(height: 6.w,),
                                        Text('${home_page_fz_text.tr}',style: TextStyle(
                                            color: whiteFontColor,
                                            fontSize: 25.sp,
                                            fontWeight: FontWeight.w600
                                        ),)
                                      ],
                                    ),
                                  ),
                                )
                              ],
                            ),
                          )
                      ),

                      //右侧信息
                      Positioned(
                          top: 620.h+110/2 - 175,
                          left: 1.sw/2 + 62/2 - 38.w,
                          child: Container(
                            width: 500.w,
                            child: Stack(
                              children: [
                                Container(
                                  child: Image.asset('assets/home/home_grid.png',width: 76,),
                                ),
                                Container(
                                  child: Image.asset(_getImageUrl(1),width: 76,),
                                ),
                                Positioned(
                                  left: 80,
                                  child: Container(
                                    child: Column(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: [
                                        Row(
                                          crossAxisAlignment: CrossAxisAlignment.end,
                                          children: [
                                            Text('${dwValue.replaceAll("-", "")}',style: TextStyle(
                                                color: whiteFontColor,
                                                fontSize:40.sp,
                                                fontWeight: FontWeight.w600,
                                                height: 1
                                            ),),
                                            SizedBox(width: 8.w,),
                                            Container(
                                              // margin: EdgeInsets.only(bottom: 4.w),
                                              child: Text('${dwUnit}',style: TextStyle(
                                                  color: greyFontColor,
                                                  fontSize: 22.sp,
                                                  fontWeight: FontWeight.w600,
                                                  height: 1
                                              ),),
                                            )
                                          ],
                                        ),
                                        SizedBox(height: 6.w,),
                                        Text(home_page_dw_text.tr,style: TextStyle(
                                            color: whiteFontColor,
                                            fontSize: 25.sp,
                                            fontWeight: FontWeight.w600
                                        ),)
                                      ],
                                    ),
                                  ),
                                )
                              ],
                            ),
                          )
                      ),
                      //顶部信息
                      Positioned(
                          top: 620.h-183,
                          left: 1.sw/2 - 62/2 - 40.w - 83/2 - 20.w,
                          child: Container(
                            width: 350.w,
                            child: Stack(
                              children: [
                                Container(
                                  child: Image.asset('assets/home/home_solar_panel.png',height: 187,),
                                ),
                                Container(
                                  child: Image.asset(_getImageUrl(0),height: 187,),
                                ),
                                Positioned(
                                  left: 20,
                                  child: Container(
                                    // width: 300.w,
                                    child: Column(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: [
                                        Row(
                                          crossAxisAlignment: CrossAxisAlignment.end,
                                          children: [
                                            Text('${gfbValue.replaceAll("-", "")}',style: TextStyle(
                                                color: whiteFontColor,
                                                fontSize:40.sp,
                                                fontWeight: FontWeight.w600,
                                                height: 1
                                            ),),
                                            SizedBox(width: 8.w,),
                                            Container(
                                              // margin: EdgeInsets.only(bottom: 4.w),
                                              child: Text('${gfbUnit}',style: TextStyle(
                                                  color: greyFontColor,
                                                  fontSize: 22.sp,
                                                  fontWeight: FontWeight.w600,
                                                  height: 1
                                              ),),
                                            )
                                          ],
                                        ),
                                        SizedBox(height: 6.w,),
                                        Text('${home_page_gfb_text.tr}',style: TextStyle(
                                            color: whiteFontColor,
                                            fontSize: 25.sp,
                                            fontWeight: FontWeight.w600
                                        ),)
                                      ],
                                    ),
                                  ),
                                )
                              ],
                            ),
                          )
                      ),
                      //底部信息
                      Positioned(
                          top: 620.h+108 ,
                          left: 1.sw/2 - 65/2 - 40.w + 30,
                          child: Container(
                            width: 500.w,
                            height:360.h - (620.h+108 - (620.h+110/2)),
                            // color: Colors.red,
                            child: Stack(
                              children: [
                                Container(
                                  child: Image.asset('assets/home/home_enegry_storage.png',height: 131,fit: BoxFit.fitHeight,),
                                ),
                                Container(
                                  child: Image.asset(_getImageUrl(2),height: 131,fit: BoxFit.fitHeight,),
                                ),
                                Positioned(
                                  bottom: 0,
                                  left: 75,
                                  child: Container(
                                    // width: 290.w,
                                    // color: Colors.green,
                                    child: Column(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: [
                                        Row(
                                          crossAxisAlignment: CrossAxisAlignment.end,
                                          children: [
                                            Text('${cndcValue.replaceAll("-", "")}',style: TextStyle(
                                                color: whiteFontColor,
                                                fontSize:40.sp,
                                                fontWeight: FontWeight.w600,
                                                height: 1
                                            ),),
                                            SizedBox(width: 8.w,),
                                            Container(
                                              // margin: EdgeInsets.only(bottom: 4.w),
                                              child: Text('${cndcUnit}',style: TextStyle(
                                                  color: Colors.white,
                                                  fontSize: 30.sp,
                                                  fontWeight: FontWeight.w600,
                                                  height: 1
                                              ),),
                                            ),
                                            SizedBox(width: 10.w,),
                                            Visibility(visible: cndcValue.isNotEmpty, child: Container(
                                              alignment: Alignment.bottomCenter,
                                              height: 40.sp,
                                              child: Column(
                                                mainAxisAlignment: MainAxisAlignment.center,
                                                children: [
                                                  SizedBox(height: 12.w,),
                                                  Container(
                                                    height: 6.sp,
                                                    width: 6.w,
                                                    decoration: BoxDecoration(
                                                        color: Colors.white,
                                                        borderRadius: BorderRadius.circular(6.w)
                                                    ),
                                                    child: Column(
                                                      children: [

                                                      ],
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            )),
                                            SizedBox(width: 10.w,),
                                            Visibility(visible: cndcValue.isNotEmpty,child: Text('$dcsocValue$dcsocUnit',style: TextStyle(
                                                color: whiteFontColor,
                                                fontSize:40.sp,
                                                fontWeight: FontWeight.w600,
                                                height: 1
                                            ),),),
                                          ],
                                        ),
                                        SizedBox(height: 6.w,),
                                        Text(cndcValue.isNotEmpty && double.parse('${cndcValue ?? '0'}') <0?'Battery Discharge': cndcValue.isNotEmpty && double.parse('${cndcValue ?? '0'}') >0?'Battery Charge':'Battery',style: TextStyle(
                                            color: whiteFontColor,
                                            fontSize: 25.sp,
                                            fontWeight: FontWeight.w600
                                        ),)
                                      ],
                                    ),
                                  ),
                                )
                              ],
                            ),
                          )
                      ),
                      //spt的logo
                      Positioned(
                        left: 1.sw/2 - 62/2 - 40.w ,
                        top: 620.h,
                        child: Container(
                          child: Image.asset('assets/home/min_spt.png',width: 62,height: 110,fit: BoxFit.cover,),
                        ),
                      ),
                      //底部电池SOC
                      Positioned(
                          top: 1230.h,
                          child: Container(
                            width: 1.sw,
                            padding: EdgeInsets.symmetric(horizontal: 30.w),
                            child: Visibility(
                              visible: true,
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  // (rdynValue!=null && rdynValue.isNotEmpty && double.parse(rdynValue??'0')>0)?
                                  // Container(
                                  //   height: 110.w,
                                  //   padding: EdgeInsets.symmetric(horizontal: 40.w),
                                  //   decoration: BoxDecoration(
                                  //       color: Color(0x2f000000),
                                  //       borderRadius: BorderRadius.circular(16.w)
                                  //   ),
                                  //   child: Row(
                                  //     children: [
                                  //       // Image.asset('assets/home/home_scgl.png',width: 32.w,),
                                  //       // SizedBox(width: 20.w,),
                                  //       Container(
                                  //         width: 220.w,
                                  //         child: Column(
                                  //           crossAxisAlignment: CrossAxisAlignment.start,
                                  //           mainAxisAlignment: MainAxisAlignment.center,
                                  //           children: [
                                  //             Row(
                                  //               crossAxisAlignment: CrossAxisAlignment.end,
                                  //               children: [
                                  //                 Text('${rdynValue.replaceAll("-", "")}',style: TextStyle(
                                  //                     color: whiteFontColor,
                                  //                     fontSize:40.sp,
                                  //                     fontWeight: FontWeight.w600
                                  //                 ),),
                                  //                 SizedBox(width: 10.w,),
                                  //                 Container(
                                  //                   margin: EdgeInsets.only(bottom: 10.w),
                                  //                   child: Text('${rdynUnit}',style: TextStyle(
                                  //                       color: greyFontColor,
                                  //                       fontSize: 22.sp,
                                  //                       fontWeight: FontWeight.w600
                                  //                   ),),
                                  //                 )
                                  //               ],
                                  //             ),
                                  //             Text('${home_page_rdynfd_text.tr}',style: TextStyle(
                                  //                 color: whiteFontColor,
                                  //                 fontSize: 25.sp,
                                  //                 fontWeight: FontWeight.w600
                                  //             ),)
                                  //           ],
                                  //         ),
                                  //       )
                                  //     ],
                                  //   ),
                                  // ):Container(
                                  //   height: 110.w,
                                  //   padding: EdgeInsets.symmetric(horizontal: 40.w),
                                  //   decoration: BoxDecoration(
                                  //       color: Color(0x2f000000),
                                  //       borderRadius: BorderRadius.circular(16.w)
                                  //   ),
                                  //   alignment: Alignment.center,
                                  //   child: Row(
                                  //     children: [
                                  //       // Image.asset('assets/home/home_scgl.png',width: 32.w,),
                                  //       // SizedBox(width: 20.w,),
                                  //       Container(
                                  //         width: 220.w,
                                  //         child: Column(
                                  //           crossAxisAlignment: CrossAxisAlignment.start,
                                  //           mainAxisAlignment: MainAxisAlignment.center,
                                  //           children: [
                                  //             Row(
                                  //               crossAxisAlignment: CrossAxisAlignment.end,
                                  //               children: [
                                  //                 Text(fzValue.isEmpty?'0':'${fzValue.replaceAll("-", "")}',style: TextStyle(
                                  //                     color: whiteFontColor,
                                  //                     fontSize:40.sp,
                                  //                     fontWeight: FontWeight.w600
                                  //                 ),),
                                  //                 SizedBox(width: 10.w,),
                                  //                 Container(
                                  //                   margin: EdgeInsets.only(bottom: 10.w),
                                  //                   child: Text('${fzUnit}',style: TextStyle(
                                  //                       color: greyFontColor,
                                  //                       fontSize: 22.sp,
                                  //                       fontWeight: FontWeight.w600
                                  //                   ),),
                                  //                 )
                                  //               ],
                                  //             ),
                                  //             Text('${home_page_fz_text.tr}',style: TextStyle(
                                  //                 color: whiteFontColor,
                                  //                 fontSize: 25.sp,
                                  //                 fontWeight: FontWeight.w600
                                  //             ),)
                                  //           ],
                                  //         ),
                                  //       )
                                  //     ],
                                  //   ),
                                  // ),
                                  Container(
                                    height: 110.w,
                                    padding: EdgeInsets.symmetric(horizontal: 40.w),
                                    decoration: BoxDecoration(
                                        color: Color(0x2f000000),
                                        borderRadius: BorderRadius.circular(16.w)
                                    ),
                                    child: Row(
                                      children: [
                                        // Image.asset('assets/home/home_scgl.png',width: 32.w,),
                                        // SizedBox(width: 20.w,),
                                        Container(
                                          width: 220.w,
                                          child: Row(
                                            children: [
                                              Image.asset('assets/home/save_momney.png',width: 48.w,),
                                              SizedBox(width: 16.w,),
                                              Column(
                                                crossAxisAlignment: CrossAxisAlignment.start,
                                                mainAxisAlignment: MainAxisAlignment.center,
                                                children: [
                                                  Text('\$$rdynValue',style: TextStyle(
                                                      color: whiteFontColor,
                                                      fontSize:40.sp,
                                                      fontWeight: FontWeight.w600
                                                  ),),
                                                  Text('Daily Saving',style: TextStyle(
                                                      color: whiteFontColor,
                                                      fontSize: 25.sp,
                                                      fontWeight: FontWeight.w600
                                                  ),)
                                                ],
                                              )
                                            ],
                                          ),
                                        )
                                      ],
                                    ),
                                  ),
                                  dcItem(),
                                ],
                              ),
                            ),
                          )
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        )
    );
  }

  _selectType(int index, dynamic selectDate) {
    // _homeViewSHow();
  }

  Widget dcItem(){
    return Container(
      height: 110.w,
      width: 340.w,
      child: Stack(
        children: [
          Container(
            child: Image.asset(double.parse(dcsocValue) > 20?'assets/home/home_battery_ing.png':'assets/home/home_battery_waring.png',height: 110.w,fit: BoxFit.fill,),
          ),
          Container(
            decoration: BoxDecoration(
                color: double.parse(dcsocValue) > 20? Color(0xff15FF43) : Color(0xffFF422D),
                borderRadius:
                 double.parse(dcsocValue)  >= 90?
                BorderRadius.all(Radius.circular(20.w)):
                BorderRadius.only(topLeft: Radius.circular(20.w),bottomLeft: Radius.circular(20.w))
            ),
            width: double.parse(dcsocValue)  >= 100 ? 340.w : double.parse(dcsocValue)/100*340.w,
            height: 110.w,
          ),
          Container(
            width: 340.w,
            height: 110.w,
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Visibility(child: SizedBox(width: 32.w,),visible: 1==1 ||double.parse(dcdlValue??'-1') > 0,),
                Visibility(child: Image.asset('assets/home/home_scgl.png',width: 32.w,),visible:double.parse(dcdlValue??'-1') > 0,),
                SizedBox(width: 26.w,),
                Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text('${dcsocValue.replaceAll("-", "")}$dcsocUnit',style: TextStyle(
                      color: double.parse(dcsocValue) > 20? Colors.black : Colors.white,
                      fontSize:40.sp,
                      fontWeight: FontWeight.w600,
                    ),),
                    Text(home_page_dcsoc_text.tr,style: TextStyle(
                        color: double.parse(dcsocValue) > 20? Colors.black : Colors.white,
                        fontSize: 25.sp,
                        fontWeight: FontWeight.w600
                    ),)
                  ],
                )
              ],
            ),
          ),
        ],
      ),
    );
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}
